1   /*
2    * Javassist, a Java-bytecode translator toolkit.
3    * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved.
4    *
5    * The contents of this file are subject to the Mozilla Public License Version
6    * 1.1 (the "License"); you may not use this file except in compliance with
7    * the License.  Alternatively, the contents of this file may be used under
8    * the terms of the GNU Lesser General Public License Version 2.1 or later,
9    * or the Apache License Version 2.0.
10   *
11   * Software distributed under the License is distributed on an "AS IS" basis,
12   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13   * for the specific language governing rights and limitations under the
14   * License.
15   */
16  
17  package scouter.javassist.bytecode;
18  
19  
20  final class LongVector {
21      static final int ASIZE = 128;
22      static final int ABITS = 7;  // ASIZE = 2^ABITS
23      static final int VSIZE = 8;
24      private ConstInfo[][] objects;
25      private int elements;
26  
27      public LongVector() {
28          objects = new ConstInfo[VSIZE][];
29          elements = 0;
30      }
31  
32      public LongVector(int initialSize) {
33          int vsize = ((initialSize >> ABITS) & ~(VSIZE - 1)) + VSIZE;
34          objects = new ConstInfo[vsize][];
35          elements = 0;
36      }
37  
38      public int size() { return elements; }
39  
40      public int capacity() { return objects.length * ASIZE; }
41  
42      public ConstInfo elementAt(int i) {
43          if (i < 0 || elements <= i)
44              return null;
45  
46          return objects[i >> ABITS][i & (ASIZE - 1)];
47      }
48  
49      public void addElement(ConstInfo value) {
50          int nth = elements >> ABITS;
51          int offset = elements & (ASIZE - 1);
52          int len = objects.length;
53          if (nth >= len) { 
54              ConstInfo[][] newObj = new ConstInfo[len + VSIZE][];
55              System.arraycopy(objects, 0, newObj, 0, len);
56              objects = newObj;
57          }
58  
59          if (objects[nth] == null)
60              objects[nth] = new ConstInfo[ASIZE];
61  
62          objects[nth][offset] = value;
63          elements++;
64      }
65  }